package mta.command.generate;

import au.com.bytecode.opencsv.CSVWriter;
import mta.command.CommandIF;
import mta.selector.PhraseSelector;

import java.io.IOException;
import java.util.HashMap;

/**
 * Magento Translation Assistant
 * Copyright (c) 2009 Dmitry Nikolaev
 * Contact author: blackliteon@gmail.com
 */
public class GeneratePatch implements CommandIF {

    private PhraseSelector selector;
    private CSVWriter writer;

    public GeneratePatch(PhraseSelector selector, CSVWriter writer) {
        this.selector = selector;
        this.writer = writer;
    }

    public void execute() {
        HashMap<String, String> phrases = selector.getPhrases();
        for (String phrase : phrases.keySet()) {
            writer.writeNext(new String[]{phrase, phrases.get(phrase)});
        }

        try {
            writer.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}